export const VIEW_LIST = 'list'
export const VIEW_CHART = 'chart'
export const TYPE_INCOME = 'income'
export const TYPE_EXPENSE = 'outcome'

export const typeArr = [TYPE_EXPENSE, TYPE_INCOME]

export const padMonthLeft = month => month < 10 ? '0'+ month : month

export const createRangeArr = (size, startAt = 0) => {
  const arr = []
  for(let i = 0; i < size; i++){
    arr[i] = startAt + i
  }
  return arr
}

export const parseToYearAndMonth = str => {
  const date = str ? new Date(str) : new Date()
  return {
    year: date.getFullYear(),
    month: date.getMonth() + 1
  }
}

export const colors = {
  blue: '#347eff',
  deepBlue: '#61dafb',
  green: '#28a745',
  red: '#dc3545',
  gray: '#555',
  lightGray: '#efefef',
  white: '#fff',
}

export const flattenArr = (arr) => {
  return arr.reduce((map, item) => {
    map[item.id] = {...item}
    return map
  }, {})
}

export const generateID = () => {
  // Math.random should be unique because of its seeding algorithm.
  // Convert it to base 36 (numbers + letters), and grab the first 9 characters
  // after the decimal.
  return '_' + Math.random().toString(36).substr(2, 9)
}
